apiready = function(){
	$(function() {
    var l = $("#hidCodeID").val();
    var e = $("#hidIsEnd").val() == "1";
    var f = $("#divBuyLoading");
    var d = $("#divRecordList");
    var j = $("#btnLoadMore");
    var c = null;
    var h = 10;
    var a = 0;
    var b = e ? "GetUserBuyListByCodeEnd": "GetUserBuyListByCode";
    var i = {
        codeID: l,
        FIdx: 1,
        EIdx: h,
        isCount: 1,
        sort: 0
    };
    var g = function() {
        var m = function() {
            return "codeID=" + i.codeID + "&FIdx=" + i.FIdx + "&EIdx=" + i.EIdx + "&isCount=" + i.isCount + "&sort=" + i.sort;
        };
        var n = function() {
            f.show();
            var itemid = localData.get('goods_id');
            if(!itemid){
                api.alert({title:'提示',msg:'数据不存在'},function(index,err){
                    appClose('buyrecord',api);
                });
                
                return;
            }
            GetJPData(config.url+"/app.php?act=buyrecordsajax&goods_id="+itemid,{sort:i.sort},function(r) {
                //Gobal.NoneHtml
                if(r['status'] == 1){
                    var s = '';
                    for(var i in r['data']){
                        s += '<ul><li class="rBg"><a href="javascript:openItem(\'userindex\','+r['data'][i].uid+',function(id){localData.set(\'userid\',id);});"><img class="lazy" data-original="'+config.upload_url+'/'+r['data'][i]['uphoto']+'"><s></s></a></li><li class="rInfo"><a href="javascript:openItem(\'userindex\','+r['data'][i].uid+',function(id){localData.set(\'userid\',id);});">' + r['data'][i].username + "</a><strong>(IP:"+r['data'][i].ip1+r['data'][i].ip2+')</strong><br><span>'+r['data'][i]['web_name_two']+'了<b class="orange">' + r['data'][i].gonumber + '</b>人次</span><em class="arial">' + r['data'][i].time + "</em></li><i></i></ul>"; 
                    }
                    $('#divRecordList').html(s);
                    lyzimg();
                }else{
                    $('#buyRecordPage').html(Gobal.NoneHtml);
                }
            });
        };
        this.initData = function() {
            i.FIdx = 1;
            i.EIdx = h;
            i.isCount = 1;
            n();
        };
        this.getNextPage = function() {
            i.FIdx = i.FIdx + h;
            i.EIdx = i.EIdx + h;
            n();
        };
    };
    
    c = new g();
    c.initData();
    var e = false;
    var k = false;
    j.click(function() {
        if (!k) {
            k = true;
            j.hide();
            c.getNextPage();
        }
    });
    
    $("#btnSort").click(function() {
        if (!k) {
            e = false;
            if (i.sort == 0) {
                $(this).html('<i></i>排序<s class="z-Sswt"></s><s class="z-Sswd"></s>');
                i.sort = 1;
            } else {
                $(this).html('<i></i>排序<s class="z-SswOn"></s><s class="z-SswNt"></s>');
                i.sort = 0;
            }
            d.empty();
            c.initData();
        }
    });
    g();
});
};
